home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / cross / GBDK-2.0.lha / GBDK / lib / free.c < prev    next >
C/C++ Source or Header  |  1998-10-01  |  578b  |  28 lines

  1. #include <sys/malloc.h>
  2.  
  3. BYTE free( void *ptr)
  4. {
  5.     /* Do a relativly safe free by only freeing vaild used hunks */
  6.     pmmalloc_hunk thisHunk;
  7.  
  8.     thisHunk = malloc_first;
  9.  
  10.     ptr = (void *)((UWORD)ptr - sizeof(mmalloc_hunk));
  11.     
  12.     while (thisHunk && (thisHunk->magic==MALLOC_MAGIC)) {
  13.         if (thisHunk == ptr) {
  14.             debug("free", "Found hunk");
  15.             if (thisHunk->status == MALLOC_USED) {
  16.                 thisHunk->status = MALLOC_FREE;
  17.                 return 0;
  18.             }
  19.             debug("free", "Attempt to free a free hunk");
  20.             return -1;
  21.         }
  22.         thisHunk = thisHunk->next;
  23.     };
  24.  
  25.     debug("free", "No hunk found");
  26.     return -2;
  27. }
  28.